package com.aididi.common.filter;

import com.aididi.common.util.JwtUtil;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName AuthFilter
 * @Description todo
 * @Author xuzexiang
 * @Data 2019/8/22 17:56
 */
@Component("authFilter")
public class AuthFilter extends FormAuthenticationFilter{

    @Autowired
    JwtUtil jwtUtil;

    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {


        return super.isAccessAllowed(request, response, mappedValue);
    }

    /**
     * @Description 获取请求头token
     * @return java.lang.String
     * @param [request]
     * @Author xuzexiang
     * @Date 2019/8/22 18:07
     **/
    private String getRequestToken(HttpServletRequest request){
        String token = request.getHeader(jwtUtil.getHeader());
        if(StringUtils.isEmpty(token)){
            token = request.getHeader(jwtUtil.getHeader());
        }
        return token;
    }
}
